#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <string>

std::string ToHex(pthread_t tid)
{
    char id[128];
    snprintf(id, sizeof(id), "0x%lx", tid);
    return id;
}

void* threadRun(void* args)
{
    std::string name = static_cast<const char*> (args);
    while(true)
    {
        
        std::cout << name << " is running..., tid: " << ToHex(pthread_self()) << std::endl;
        sleep(3);
    }
}


int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, threadRun, (void*)"thread-1"); 
    std::cout << "new thread tid: " << tid << std::endl;
    pthread_join(tid, nullptr);
    return 0;
}